<?php

use Faker\Factory as Faker;
use App\Models\Slideshow;
use App\Repositories\SlideshowRepository;

trait MakeSlideshowTrait
{
    /**
     * Create fake instance of Slideshow and save it in database
     *
     * @param array $slideshowFields
     * @return Slideshow
     */
    public function makeSlideshow($slideshowFields = [])
    {
        /** @var SlideshowRepository $slideshowRepo */
        $slideshowRepo = App::make(SlideshowRepository::class);
        $theme = $this->fakeSlideshowData($slideshowFields);
        return $slideshowRepo->create($theme);
    }

    /**
     * Get fake instance of Slideshow
     *
     * @param array $slideshowFields
     * @return Slideshow
     */
    public function fakeSlideshow($slideshowFields = [])
    {
        return new Slideshow($this->fakeSlideshowData($slideshowFields));
    }

    /**
     * Get fake data of Slideshow
     *
     * @param array $postFields
     * @return array
     */
    public function fakeSlideshowData($slideshowFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'type' => $fake->randomDigitNotNull,
            'name' => $fake->word,
            'skip_id' => $fake->randomDigitNotNull,
            'skip_url' => $fake->text,
            'image' => $fake->text,
            'sort' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $slideshowFields);
    }
}
